package cn.wolfcode.shop.cloud.common;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * Created by wolfcode-lanxw
 */
@Setter@Getter@NoArgsConstructor@AllArgsConstructor
public class Result<T> {
    public static final Integer SUCCESS_CODE = 200;
    public static final String SUCCESS_MSG = "操作成功";
    private Integer code;
    private String msg;
    private T data;

    public static <T> Result<T> success(){
        return success(null);
    }

    public static <T> Result<T> success(T data){
        return new Result<>(SUCCESS_CODE,SUCCESS_MSG,data);
    }
    public static <T> Result<T> success(String msg, T data){
        return new Result<>(SUCCESS_CODE,msg,data);
    }
    public static Result<CodeMsg> error(CodeMsg codeMsg){
        return new Result<>(codeMsg.getCode(),codeMsg.getMsg(),null);
    }
    public Boolean hasError(){
        return !this.code.equals(SUCCESS_CODE);
    }
}
